﻿using BarManager.Core.BusinessRules.Interfaces.Specification;
using BarManager.Core.DomainService;
using BarManager.Core.Entity;
using System.Collections.Generic;

namespace BarManager.Core.BusinessRules.Specification
{
    public class ZonaDeleteSpecification : BaseSpecification<Zona>, IZonaSpecification
    {
        private Zona Zona = null;

        public ZonaDeleteSpecification(IZonaRepository repository)
            :base(repository)
        {
        }

        public override bool IsSatisfiedBy(Zona entity)
        {
            Zona = BaseRepository.Get(x => x.Descripcion == entity.Descripcion);
            return (Zona.Mesas.Count == 0);
        }

        public override IEnumerable<string> GetErrorMessage()
        {
            if (Zona != null) yield return string.Format("No se puede eliminar la zona porque contiene mesas {0}", Zona.Mesas.Count);
            yield break;
        }
    }
}
